import React,{Component} from 'react'
import { message,Spin} from 'antd';
import * as pub from '../../config/public';
import * as fetch from '../../config/fetch';
import {browserHistory} from 'react-router';
class ArticleExamine extends Component {
	constructor(args) {
		super()
		this.state = {
			essay:{},
			loading:false,
			essayPhotos:[]
		}
	}
	sub(flag) {
		//console.log(1233,this.refs.auditOpinion.value)
		if(this.refs.auditOpinion.value.replace(/^ +| +$/g,'')===""&&flag==="2"){
			message.error('请输入审核意见', 3);
			return;
		}
		let body = {};
		body.auditOpinion = this.refs.auditOpinion.value;
		body.checkState = flag;
		body.essayId = this.props.params.id;
		pub.loading(this,true);
		fetch.checkArticle(body).then((data) => {
			if (data.result === 'RC100') {
				pub.jumpHistory.push('/admin/ArticleManage');
			} else if(data.result===undefined){
				message.warning(data.msg, 3);
				pub.jumpHistory.push('/admin/ArticleManage');
			}else{
				message.error(data.errMsg, 3);
			}
			pub.loading(this,false);
		}, (res) => {
			pub.loading(this, false);
			pub.reject(res);
		})
	}
	componentWillMount() {
		pub.loading(this,true);
		fetch.checkArticlePage({essayId:this.props.params.id}).then((data)=>{
			if (data.result === 'RC100') {
				this.setState({
					essay:data.essay,
					value:data.essay.auditOpinion,
					essayPhotos:data.essay.essayPhotos?data.essay.essayPhotos:[]
				})
			} else {
				message.error(data.errMsg, 3);
			}
			pub.loading(this,false);
		}, (res) => {
			pub.loading(this, false);
			pub.reject(res);
		})
	}
	numberInputs=(e)=>{
		let value=e.target.value
		e.target.value=value.replace(/[@#%&{}?/><[()（）【】{}《》'“‘”’]+/g,'');
	}
	changeValue(){
		this.setState({
			value:this.refs.auditOpinion.value
		})
	}
	render(){
		let essay = this.state.essay;
		return(
			<div className="container">
				<div className="common-title">文章审核</div>
				<Spin spinning={this.state.loading} tip="加载列表中...">
				<div className="article-box bg-FFFFFF box-shadow">
					<h3>{essay.essayTitle}</h3>
						<p className="time" style={{ textIndent: "2em" }}>{essay.userRealName}&nbsp;&nbsp;&nbsp;{essay.createTime?pub.formatTimestamp(essay.createTime):''}</p>
					<div className="article-cont" style={{minHeight:'259px'}}>
						<pre style={{whiteSpace: 'pre-wrap'}}>{essay.essayNote}</pre>
						{
									   this.state.essayPhotos.map((item,index)=>{
										   return(
                                                <img key={index}  src={pub.getFile(item.essayPhotoPath)} alt='test' style={{maxWidth: '300px',minWidth: '250px',height:'250px',margin:'20px auto'}}/>
										   )
									   })
						}
					</div>
					<h3>审核意见</h3>
					<textarea placeholder="请输入审核意见" ref='auditOpinion' onKeyUp={this.numberInputs} value={this.state.value} onChange={this.changeValue.bind(this)}></textarea>
					<div className="row submit-btn mar-b-20 mar-t-20 text-center">
						<a className="btn btn-red" onClick={()=>this.sub(2)}>不通过</a>
						<a className="btn btn-blue" onClick={()=>this.sub(1)}>通过</a>
					</div>
				</div>
				</Spin>
			</div>
			)
	}
}
export default ArticleExamine